package com.winner.crmsoftware.customers;

import java.util.ArrayList;
import java.util.zip.Inflater;

import com.winner.crmsoftware.main.R;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListCustomerAdapter extends ArrayAdapter<Customer> {

	Context mContext;
	int layoutResourceId;
	ArrayList<Customer> data = null;
		
	public ListCustomerAdapter(Context mContext, int layoutResourceId, ArrayList<Customer> data) {
		super(mContext, layoutResourceId, data);
		
		this.layoutResourceId = layoutResourceId;
		this.mContext = mContext;
		this.data = data;
		// TODO Auto-generated constructor stub
	}	
		
	@SuppressLint("ViewHolder") @Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		View rowView = inflater.inflate(R.layout.customer_item, parent, false);
		TextView tv_name = (TextView) rowView.findViewById(R.id.tv_name);
		TextView tv_distace = (TextView) rowView.findViewById(R.id.tv_distance);
		TextView tv_address = (TextView) rowView.findViewById(R.id.tv_address);
		
		Customer customer = data.get(position);
		if (customer != null) {
			tv_name.setText(customer.getName());
			tv_distace.setText("" + customer.getDistace() + " Km");
			tv_address.setText(customer.getAddress());
			
		}
		return rowView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

}
